package cn.sytton.taffe.monitor.model;

import cn.sytton.taffe.framework.security.entity.LoginUser;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 在线用户模型
 *
 * @author skyrock
 */
@Schema(description = "在线用户")
@Data
@NoArgsConstructor
public class OnlineUser {
    private String token;
    private String loginName;
    private String userName;
    private String userCode;
    private String ip;                 //登录IP
    private String loginLocation;      //登录地点
    private String browser;            //浏览器类型
    private String os;                 //操作系统
    private String email;              //用户邮箱
    private String cellphone;          //手机号
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat
    private Date loginTime;       //登录时间戳
    @JsonFormat
    private Date tokenExpireTime; //令牌时间戳

    public OnlineUser(LoginUser loginUser) {
        this.token = loginUser.getTokenId();
        this.loginName = loginUser.getLoginName();
        this.userName = loginUser.getUserName();
        this.userCode = loginUser.getUserCode();
        this.ip = loginUser.getIp();
        this.loginLocation = loginUser.getLoginLocation();
        this.browser = loginUser.getBrowser();
        this.os = loginUser.getOs();
        this.email = loginUser.getEmail();
        this.cellphone = loginUser.getCellphone();
        this.loginTime = new Date(loginUser.getLoginTimeStamp());
        this.tokenExpireTime = new Date(loginUser.getTokenExpireTimeStamp());
    }
}
